package MyBot;

import cz.cuni.pogamut.Client.*;
import cz.cuni.pogamut.Client.RcvMsgEvent;
import cz.cuni.pogamut.introspection.PogProp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.logging.Level;

import cz.cuni.pogamut.Client.Agent;
import cz.cuni.pogamut.MessageObjects.*;


import MyBot.deliberative.*;
import MyBot.executive.*;
import MyBot.reactive.*;

/**
 * PLAYGROUND for the platform testers :-)
 *
 * This bot contains a lot of code and isn't that stupid at all! This is the Hunter.
 * It collects weapons in map, runs for medkits when it's health is low, trying to kill anybody
 * from different team on sight. Well it's not clever as it doesn't trying to follow it's
 * prey around the corner. And that is where you can step in and start to play with our platform!
 * <p>
 * derived from AdvancedBot
 * <p>
 * Plan / if-then rules organization:
 * <ol>
 * <li> do you see enemy and possess better weapon? 
 *                               -> go to CHANGE_WEAPON    (change to better weapon)	
 * <li> do you see enemy?        -> go to ENGAGE	   (start shooting / hunt the enemy / change weapon)
 * <li> are you shooting?        -> go to STOP_SHOOTING	   (stop shooting, you've lost your target) 
 * <li> are you being shot?      -> go to HIT		   (turn around - try to find your enemy)   
 * <li> are you walking? 	 -> go to WALKING	   (check WAL)
 * <li> are you following enemy? -> go to PURSUE	   (run to enemy last position)
 * <li> do you see item?	 -> go to GRAB_ITEM	   (pick the most suitable item and run for it)	
 * <li> are you hurt?		 -> go to MED_KITS	   (run around list of Health items - MedKits, HealthVials)
 * <li> have nothing to do?	 -> go to RUN_AROUND_ITEMS (randomize array of known items and run around 
 * 													  those items using GET_PATH)	
 * </ol>
 * Each state you see here can be found in method - stateXXX.
 * <p>
 * It doesn't look hard, but it's not so simple - check out respective methods
 * for those states and then think about how you could improve this Hunter.
 * <p>
 * Hunter is also counting it's deaths and frag for itself.
 * 
 * @author Ondra
 */
public class MyAgent extends Agent {

    protected DeliberativeLayer m_deliberativeLayer = null;
    protected ExecutiveLayer m_executiveLayer = null;
    protected ReactiveLayer m_reactiveLayer = null;


    public MyAgent() {
        super();
        this.log.setLevel(Level.INFO);
        this.platformLog.setLevel(Level.INFO);

        m_reactiveLayer = new ReactiveLayer(memory, body, gameMap, log, platformLog);
        m_executiveLayer = new ExecutiveLayer(memory, body, gameMap, m_reactiveLayer);
        m_deliberativeLayer = new DeliberativeLayer(memory, body, gameMap, m_executiveLayer);
        

    }

    @Override
    protected void prePrepareAgent() {
        this.body.initializer.setTeam(1);
        m_deliberativeLayer.prePrepareAgent();
        m_executiveLayer.prePrepareAgent();
        m_reactiveLayer.prePrepareAgent();
    }

    /**
     * Prepares list of agent will run around. <br>
     * He will run only around weapons and armors so he will be armored and armed soon
     */
    @Override
    protected void postPrepareAgent() {
        m_deliberativeLayer.postPrepareAgent();
        m_executiveLayer.postPrepareAgent();
        m_reactiveLayer.postPrepareAgent();
    }

    /**
     * MyAgent method of the bot's brain - we're going to do some thinking about
     * the situation we're in (how it's unfair to be the bot in the gloomy world
     * of UT2004 :-).
     * <p>
     * Check out the javadoc for this class - there you find a basic concept
     * of this bot.
     */
    @Override
    protected void doLogic() {
        m_deliberativeLayer.doLogic();
        m_executiveLayer.doLogic();
        m_reactiveLayer.doLogic();


    }


    /**
     * This is method from interface RcvMsgListener, every message that goes from GB2004 to Agent goes 
     * also through here.
     * We're using it to count the frags and deaths of the hunter.
     */
    @Override
    public void receiveMessage(RcvMsgEvent e) {
        // DO NOT DELETE! Otherwise things will screw up! Agent class itself is also using this listener...
        super.receiveMessage(e);

        m_deliberativeLayer.receiveMessage(e);
        m_executiveLayer.receiveMessage(e);
        m_reactiveLayer.receiveMessage(e);
    }
    /**
     * NOTE: this method MUST REMAIN DEFINED + MUST REMAIN EMPTY, due to technical reasons.
     */
    public static void main(String[] Args) {
    }
}
